$().ready(function() {

	// validate signup form on keyup and submit
	$("#signupForm").validate({
		rules: {
			firstname: "required",
			lastname: "required",
			username: {
				required: true,
				minlength: 2
			},
			password: {
				required: true,
				minlength: 5
			},
			confirm_password: {
				required: true,
				minlength: 5,
				equalTo: "#password"
			},
			email: {
				required: true,
				email: true
			},
			agree: "required"
		},
		
		messages: {
			firstname: "Completati numele",
			lastname: "Completati prenumele",
			username: {
				required: "Completati username-ul",
				minlength: "Username-ul dvs trebuie sa contina cel putin 2 caractere"
			},
			password: {
				required: "Completati parola",
				minlength: "Parola trebuie sa aibe cel putin 5 caractere"
			},
			confirm_password: {
				required: "Confirmati parola",
				minlength:  "Parola trebuie sa aibe cel putin 5 caractere",
				equalTo: "Parolele nu coincid"
			},
			email: "Introduceti o adresa de e-mail valida",
			agree: "Va rugam acceptati termenii si conditiile"
		}
	});
	
	// propose username by combining first- and lastname
	$("#username").focus(function() {
		var firstname = $("#firstname").val();
		var lastname = $("#lastname").val();
		if(firstname && lastname && !this.value) {
			this.value = firstname + "." + lastname;
		}
	});
	
});
